// 登录和注册的仓库
import { setToken, getToken, removeToken } from '@/utils/token';
import { reqUserLogin, reqUserRegister } from "@/api"
const state = {
    token: getToken(),
}
const mutations = {
    USERLOGIN(state, token) {
        state.token = token;
    }
}
const actions = {
    // 用户注册
    async userRegister({ commit }, user) {
        let result = await reqUserRegister(user);
        if (result.code == 200) {
            return 'ok';
        } else {
            return Promise.reject(new Error('faile'));
        }
    },
    // 用户登录
    async userLogin({ commit }, user) {
        let result = await reqUserLogin(user);
        if (result.code == 200) {
            commit('USERLOGIN', result.data.token)
            setToken(result.data.token)
            return 'ok';
        } else {
            return Promise.reject(new Error('faile'));
        }
    }
}
const getters = {

}
export default {
    state,
    mutations,
    actions,
    getters
}